﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AudioCore.Entity;
using AudioCore.DAO;
using System.Data;

namespace AudioCore.Biz
{
    public class VisitedBiz : BaseBiz
    {
        public int AddVisited(VisitedEntity entity)
        {
            try
            {
                using (VisitedDao dao = new VisitedDao())
                {
                    return dao.InsertEntity(entity, typeof(VisitedEntity));
                }
            }
            catch (Exception e)
            {
                //do nothing
            }
            return -1;
        }

        public int UpdateVisited(VisitedEntity entity)
        {
            try
            {
                using (VisitedDao dao = new VisitedDao())
                {
                    return dao.UpdateEntity(entity, typeof(VisitedEntity));
                }
            }
            catch (Exception e)
            {
                //do nothing
            }
            return -1;
        }

        public int DeleteVisited(int visitedID)
        {
            try
            {
                using (VisitedDao dao = new VisitedDao())
                {
                    return dao.DeleteEntity(visitedID);
                }
            }
            catch (Exception e)
            {
                //do nothing
            }
            return -1;
        }

        public VisitedEntity GetVisitedByID(int visitedID)
        {
            try
            {
                using (VisitedDao dao = new VisitedDao())
                {
                    DataTable table = dao.SelectEntityByID(visitedID);
                    if (table.Rows.Count > 0)
                    {
                        return (VisitedEntity)BaseBiz.MapDataRowToObject(table.Rows[0], typeof(VisitedEntity));
                    }
                }
            }
            catch (Exception e)
            {
                //do nothing
            }
            return null;
        }

        public VisitedEntity GetVisited(int accountID, int itemID, int itemType)
        {
            try
            {
                using (VisitedDao dao = new VisitedDao())
                {
                    DataTable table = dao.GetVisisted(accountID, itemID, itemType);
                    if (table.Rows.Count > 0)
                    {
                        return (VisitedEntity)BaseBiz.MapDataRowToObject(table.Rows[0], typeof(VisitedEntity));
                    }
                }
            }
            catch (Exception e)
            {
            }
            return null;
        }
    }
}
